package org.fei.ClassDiagram.data;

import org.fei.ClassDiagram.Editor.Wrappers.VariableDataWrapper;
import org.fei.ClassDiagram.WindowComponents.Message;

/**
 * Trieda ktora vytvori retazec v spravnom UML formate pre datove cleny tried.
 * @author Tomas
 */
public class VariableData extends Data {
    
    protected VariableDataWrapper var;
    
    public VariableData(VariableDataWrapper variable) {
        var = variable;
        
        this.generateRepresent();
    }
    public void generateRepresent() {
        this.represent = var.accessToString() + " ";
        this.represent += var.getName() + ": ";
        
        if (var.getTypeSignature() == null) {
            this.represent += var.getReturnType();
        }
        else if (var.getTypeSignature().startsWith("T")) {
            //Message.showMessage(var.getTypeSignature());
            String typeSignature = var.getTypeSignature();
            String type = new String();
            boolean start = false;
            
            for (int i = 0; i < typeSignature.length(); i++) {
                // tu konci
                if (typeSignature.charAt(i) == ';') {
                    start = false;
                    continue;
                }
                // tu sa zapise
                if (start == true) {
                    type += typeSignature.charAt(i);
                }
                // tu zacina
                if (typeSignature.charAt(i) == 'T') {
                    start = true;
                    continue;
                }
            }
            this.represent += type;
        }
        else {
            //Message.showMessage(var.getTypeSignature());
            this.represent += var.getReturnType(); 
        }
    }

    @Override
    public String toString() {
        return this.represent;
    }
    
    public String getName() {
        return var.getName();
    }

    public VariableDataWrapper getVar() {
        return var;
    }
}